package serviceimpl;

import bean.Teacher;
import dao.TeacherDaoInter;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import service.TeacherServiceInter;

import java.util.LinkedHashMap;
import java.util.List;

import Tool.ToolInter;

/**
 * Created by Administrator on 2017/4/25.
 */
public class TeacherServiceImpl implements TeacherServiceInter {

    private TeacherDaoInter teacherDaoImpl;
    private ToolInter ToolImpl;
    
    public TeacherDaoInter getTeacherDaoImpl() {
        return teacherDaoImpl;
    }

    public void setTeacherDaoImpl(TeacherDaoInter teacherDaoImpl) {
        this.teacherDaoImpl = teacherDaoImpl;
    }

    public String queryAllTeacher() {
        List<Teacher> teacher = this.getTeacherDaoImpl().queryAll();
        JSONArray jsonArray = new JSONArray();
        JSONObject obj = new JSONObject();
        JSONArray practiceReport = new JSONArray();
        for (int i = 0; i < teacher.size(); i++) {
            LinkedHashMap report = new LinkedHashMap();
            try {
                report.put("tName", teacher.get(i).getTname());
                report.put("tSex", teacher.get(i).getTsex());

                report.put("tEducation", teacher.get(i).getTeducation());
                report.put("tPicture", teacher.get(i).getTpicture());
                report.put("tProject", teacher.get(i).getTproject());
                report.put("tWork", teacher.get(i).getTwork());
                report.put("tPaper", teacher.get(i).getTpaper());
                report.put("tPatent", teacher.get(i).getTpatent());
                report.put("tReward", teacher.get(i).getTreward());
                JSONObject json = JSONObject.fromObject(report);
                practiceReport.add(json);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        obj.put("data", practiceReport);
        jsonArray.add(obj);
        return jsonArray.toString();
    }

	public ToolInter getToolImpl() {
		return ToolImpl;
	}

	public void setToolImpl(ToolInter toolImpl) {
		ToolImpl = toolImpl;
	}
}
